package com.situ.b2c.index.service;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mysql.cj.Session;
import com.situ.b2c.pojo.User;
import com.situ.b2c.register.dao.UserDao;

public class IndexService {
	UserDao userDao = new UserDao();
	
	public int doUserLogin(String userCode,String userPass,HttpServletRequest request) {
		int result = 0;
		User user = userDao.selectOneByCodeAndPass(userCode, userPass);
		//System.out.println(user);
		if (user != null) {
			int isLock = user.getIsLock();
			if (isLock == 0) {
				
				user.setLoginCount(user.getLoginCount()+1);
				user.setLoginIp(request.getRemoteAddr());
				user.setLoginDate(new Date());
				userDao.update(user);
				
				HttpSession session = request.getSession();
				session.setAttribute("login_user", user);
				result = 1;
			}else {
				result = 0;
			}
		}else {
			result = 2;
		}
		return result;

	}
}
